// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

#include "Body.h"
#include "hydroapp.h"

Body::Body(Body* _parent, double _mass)
{
	parent = _parent;
	node = app->staticNode->createChildSceneNode();
	mass = _mass;
	node->setInheritOrientation(false);
	children = new std::vector<Body*>();
	reforientation = Quat();
	spin = Quat();
	position = Vec3(0,0,0);
	gposition = Vec3(0,0,0);
	rposition = Ogre::Vector3(0,0,0);
	velocity = Vec3(0,0,0);
	node->setPosition(rposition);
}

Body::~Body(void)
{
	std::vector<Body*>::iterator iter;
	for (iter = children->begin(); iter != children->end(); iter++) {
		delete (*iter);
	}
	delete children;
	//delete node;
}

void Body::update()
{
	if (parent != NULL)
		gposition = position + parent->gposition;
	else
		gposition = position;
	for (iter = children->begin(); iter != children->end(); iter++) {
		(*iter)->update();
	}
}
